package com.suse.mybatisdemo.mapper;


import com.suse.mybatisdemo.model.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select * from userinfo")
    List<UserInfo> queryUserInfos();

    @Select("select * from userinfo where id = #{id}")
    UserInfo queryUserInfo(@Param("id") Integer id);

    @Select("select * from userinfo where id = #{id} and username = #{name}")
    UserInfo queryUserInfo2(@Param("id") Integer id,@Param("name") String name);

    @Insert("insert into userinfo (username,`password`, age, gender, phone, delete_flag) " +
            "values(#{userInfo.username},#{userInfo.password},#{userInfo.age}," +
            "#{userInfo.gender},#{userInfo.phone},#{userInfo.deleteFlag})")
    Integer insert(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from userinfo where id = #{id}")
    Integer delete(Integer id);

    @Update("update userinfo set password = #{password} where id = #{id}")
    Integer update(UserInfo userInfo);

    @Insert("<script>insert into userinfo (username, password," +
            "<if test='age!=null'> age,</if> " +
            "gender, phone) " +
            "values (#{username}, #{password}, " +
            "<if test='age!=null'> #{age},</if> " +
            "#{gender}, #{phone}) " +
            "</script>")
    Integer insertByCondition(UserInfo userInfo);
}
